local addonName = "PSLibBar";
local moduleName = "Plugins";
local Addon = LibStub("AceAddon-3.0"):GetAddon(addonName);
local Module = Addon:NewModule(moduleName);
local L = LibStub("AceLocale-3.0"):GetLocale(addonName);

Module.optionTable = 
{
	order = 1.2,
	name = L["Plugins.Settings.Title"],
	type = "group",
	handler = Module, get = "GetValue", set = "SetValue",
	args = 
	{ 
		
	}
}

local pluginDetailsOT = 
{
	type = "group",
	args = 
	{ 
		title = 
		{
			order = 1.0,
			type = "description",
			fontSize = "large",
		},
		version = 
		{
			order = 1.1,
			type = "description",
			fontSize = "small",
		},
		author =
		{
			order = 1.2,
			type = "description",
			fontSize = "small",
		},
		description =
		{
			order = 1.3,
			type = "description",
			fontSize = "small",
		},
	}
}
		
Module.plugins = {};
function Module:OnInitialize()
	for key,value in pairs(Module.plugins) do		
		local detailsOT = PS:CloneObject(pluginDetailsOT);
		
		detailsOT.name = value.name;
		detailsOT.args.title.name = string.format(L["Plugins.Settings.PluginNameTemplate"],value.name);
		detailsOT.args.version.name = string.format(L["Plugins.Settings.PluginVersionTemplate"],value.version);
		detailsOT.args.author.name = string.format(L["Plugins.Settings.PluginAuthorTemplate"],value.author);
		detailsOT.args.description.name = string.format(L["Plugins.Settings.PluginDescriptionTemplate"],value.description);
		
		Module.optionTable.args[key] = detailsOT;
	end
	
end

function Module:OnEnable()
	
end

function Module:OnSettingsChanged(settings)
	
end

local pluginValidationTable = 
{
	["name"] 		= PS:v("string"),
	["version"] 	= PS:v("number"),
	["factory"]		= PS:v("table"),
	["description"] = PS:v("string","opt"),
	["author"] 		= PS:v("string","opt"),
}

function Addon:RegisterPlugin(name, plugin)
	if(PS:Validate(plugin, pluginValidationTable)) then
		if(not Module.plugins[name] 
		   or Module.plugins[name].version < plugin.version) 
		then
			Module.plugins[name] = plugin;
		end
	end
end